package com.example.security.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@org.springframework.stereotype.Controller
public class Controller {


    /**
     * 主页面
     * @return
     */
    @RequestMapping("/home")
    public String home(){
        return "home";
    }

    /**
     * 用户管理
     * @return
     */
    @RequestMapping("/users")
    public String users(){
        return "users";
    }

    /**
     * 角色管理
     * @return
     */
    @RequestMapping("/roles")
    public String roles(){
        return "roles";
    }

    /**
     * 菜单管理
     * @return
     */
    @RequestMapping("/menus")
    public String menus(){
        return "menus";
    }

    /**
     * 其他管理
     * @return
     */
    @RequestMapping("/others")
    public String others(){
        return "others";
    }


    /**
     * 其他管理
     * @return
     */
    @RequestMapping("/logout")
    public String logout(){
        return "logout";
    }

    /**
     * 错误提示
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping("/login/error")
    public void error(HttpServletRequest request,HttpServletResponse response) throws IOException {
        AuthenticationException authentication = (AuthenticationException) request.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION");
        response.getWriter().write(authentication.toString());
        response.getWriter().flush();
    }


}